﻿hpxAdminApp.controller('setCustserMsgController', function (exportService, $rootScope, $interval, $scope, $stateParams, $state, API_URL, NgTableParams, custserService,  EXPORT_URL) {
    var emptyEntity = {};
    var newEntity = angular.copy(emptyEntity, newEntity);
    $scope.filter = {
        
    };
    $scope.custserGroupData = [
        {
            "groupCode": "ALL",
            "groupName": "所有"
        }, {
            "groupCode": "REGISTER",
            "groupName": "注册"
        }, {
            "groupCode": "BILL",
            "groupName": "票据"
        }, {
            "groupCode": "NULL",
            "groupName": "无"
        }
    ]
    

    //获取所有未审核或者已审核的票据资料信息
    $scope.tableParams = new NgTableParams({'sorting': {'publishing_time': 'desc'}}, {
        getData: function (params) {
            console.log($scope.filter)
            return custserService.searchCustserList(params,$scope.filter.custserName, $scope.filter.custserPhone, $scope.filter.custserGroup, $scope.filter.isOnline).then(function (data) {
                $scope.first = $scope.getFirst(params);
                console.log(data);
                return data;
            });
        }
    });
    //刷新
    $scope.refresh = function () {
        $scope.tableParams.reload();
    };

    $scope.edit = function (data) {
        if (data == null) {
            $scope.model = newEntity;       //弹出新建窗口
            $('#modal-add').modal('show');
        }
        else {
            $scope.model = angular.copy(data);      //弹出修改窗口
            $('#modal-edit').modal('show');
        }
    };
    $scope.save = function () {
        if ($scope.model.id == null) {
            //新建
            custserService.add($scope.model).then(function (data) {
                $scope.tableParams.reload();
                angular.copy(emptyEntity, newEntity);
                $scope.editForm.$setPristine();
                $('#modal-add').modal('hide');
            });
        }
        else {
            //修改
            custserService.update($scope.model).then(function (data) {
                $scope.tableParams.reload();
                $scope.editForm.$setPristine();
                $('#modal-edit').modal('hide');
            });
        }
    };
    //删除某条地址信息；刷新列表
    $scope.remove = function (data) {
        if (confirm('确定要删除 ' + data.custserName + ' 吗？')) {
            custserService.remove(data.id).then(function (data) {
                $scope.tableParams.reload();
            });
        }
    };
   

});
